Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MDEV-34391 SET PATH variable and resolution for stored routine invocations #3796

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

iqbal-rsec
Copy link

@iqbal-rsec iqbal-rsec commented Jan 28, 2025

  • The Jira issue number for this PR is: MDEV-34391

Description

Implement the SET PATH statement. The grammar differs from the Jira ticket where the equal sign is required:
SET PATH= 'schema1, schema2, schema3';
Schemas within the session PATH variable will be used to resolve unqualified and qualified routine invocations.
To determine whether or not a particular routine exists within a schema/database lookups has to be performed on the proc table, so performance is impacted. To alleviate this, the PATH is empty by default - routines will be resolved using the current database as it was originally done before this implementation.

Original PR is #3566, this PR has some additional changes that fixes/simplify the parser:

  • Refactored PATH parser code and fixed a bug where commas inside quotes are still treated as separator.
  • Moved path cache to system_variables for consistency with other variables
  • Changed path SET grammar to require = for consistency with other variables
  • Changed path cache to be a simple static array both for easier memory management. Only 16 schemas are supported per session, we do not want too many schemas in the path anyway since it will impact performance.
  • Add support for internal schemas (mariadb_schema, oracle_schema) in paths.
  • Set default PATH to empty
  • Make views invariant to current path
  • Invalidate sp caches when session path has been changed so that stored routines are recompiled to use the new paths
  • Disallow session path setting inside stored routines
  • Add tests
    • Ensure that SUPER permission is needed to set GLOBAL PATH
    • Tests were added to allow database names that contains commas or double quotes
    • Test internal schemas in PATH
    • Test view invariance with respect to PATH

Release Notes

New system variable path has been added.

How can this PR be tested?

mysql-test/mtr path_basic path_resolution

Basing the PR against the correct MariaDB version

  • This is a new feature or a refactoring, and the PR is based against the main branch.
  • This is a bug fix, and the PR is based against the earliest maintained branch in which the bug can be reproduced.

PR quality check

  • I checked the CODING_STANDARDS.md file and my PR conforms to this where appropriate.
  • For any trivial modifications to the PR, I am ok with the reviewer making the changes themselves.

Definition
==========
Implement the SET PATH statement. The grammar differs from the Jira
ticket where the equal sign is required:
```
SET PATH= 'schema1, schema2, schema3';
```

Function
--------
In MariaDB, the SQL-path will also be used to lookup packages in
package routine invocations, so the following script:

  SET PATH='sys';
  SELECT UTL_ENCODE.BASE64_DECODE('data');

invokes SYS.UTL_ENCODE.BASE64_DECODE('data'), i.e. the function
BASE64_DECODE() in the packge UTL_ENCODE in the database SYS
(if such package and package routine exist).

MariaDB implementation details
------------------------------
The ticket's requirement stated the grammar should support delimited
identifiers with backticks or double quotes within the string quote,
ie: the single tick. A simple parser was implemented to handle this
requirement in Sql_path::from_text.

Only 16 schemas are supported per session - we do not want too many
schemas in the path anyway since it will impact performance. This also
means that the path cache is a simple static array for easier memory
management.

Internal schemas (mariadb_schema, oracle_schema) are supported in paths.
Only the first internal schema in the path will be used to resolve native
routines to their respective versions.
@iqbal-rsec iqbal-rsec force-pushed the feature/MDEV-34391_path_squashed branch from 8f87435 to 9245539 Compare January 28, 2025 09:29
@cvicentiu cvicentiu added the External Contribution All PRs from entities outside of MariaDB Foundation, Corporation, Codership agreements. label Jan 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
External Contribution All PRs from entities outside of MariaDB Foundation, Corporation, Codership agreements.
Development

Successfully merging this pull request may close these issues.

3 participants